package org.duang.handles;

import java.util.Iterator;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.duang.config.InstanceFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Handles {
	
	private static Logger logger = LoggerFactory.getLogger(Handles.class);
	
	public static void init() {
		//ActionHandle必须添加到最后
		InstanceFactory.getHandles().add(new ActionHandle());
		printHandles();
	}
	
	private static void printHandles() {
		for(IHandle handle : InstanceFactory.getHandles()){
			logger.warn(handle.getClass().getName() +" start success...");	
		}
	}
	
	
	public static void execute(String target, HttpServletRequest request, HttpServletResponse response) throws Exception{
		for(Iterator<IHandle> it = InstanceFactory.getHandles().iterator(); it.hasNext();) {
			it.next().execute(target, request, response);
		}
	}
	
	
}
